<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>数据导入</title>
	<meta name="decorator" content="blank"/>
	<script type="text/javascript">
	$(function(){
		$("#myFile").change(function () {
	        var filepath = $("input[name='file']").val();
	        var extStart = filepath.lastIndexOf(".");
	        var ext = filepath.substring(extStart, filepath.length).toUpperCase();
	        if (ext != ".xls" && ext != ".XLS" && ext != ".XLSX" && ext != ".xlsx") {
	          alertx("文件限于xls和xlsx格式");
	          $("#fileSize").text("");
	          $("#myFile").val("");
	          return false;
	        }
	        var file_size = 0;
	        if ($.browser.msie) {
	          var img = new Image();
	          img.src = filepath;
	          while (true) {
	            if (img.fileSize > 0) {
	              if (img.fileSize > 3 * 1024 * 1024) {
	                alertx("文件不大于100MB。");
	                $("#myFile").val("");
	              } else {
	                var num03 = img.fileSize / 1024;
	                num04 = num03.toFixed(2)
	                $("#fileSize").text(num04 + "KB");
	              }
	              break;
	            }
	          }
	        } else {
	          file_size = this.files[0].size;
	          var size = file_size / 1024;
	          if (size > 1024*20) {
	            alert("上传的文件大小不能超过20M！");
	            $("#myFile").val("");
	          } else {
	            var num01 = file_size / 1024;
	            num02 = num01.toFixed(2);
	            $("#fileSize").text(num02 + " KB");
	          }
	        }
	        return true;
	      });
	});
	function beforeSubmit(){
		if($("#myFile").val()==""){
			alertx("请上传数据!");
			return;
		}
		return servicePassword(submitForm,$("#username").val());
	}
	function submitForm(){
		var flag = false;
		var url = "${ctx}/ins/insData/importFile?table.id="+$("#tableId").val();
		var formData = new FormData($( "#inputForm" )[0]);
        $.ajax({
            type: 'POST',
            url : url,
            async:false,
            processData:false,
            contentType:false,
            data: formData,             //获取表单数据
            dataType:"text",
            success : function(data) {
            	if((data+"").indexOf("error:")>-1){
            		$("#fileSize").text("");
      	            $("#myFile").val("");
                    alertx((data+"").split(":")[1]);
                    return false;
            	}else{
            		 flag = true;
                     alert(data);
                     parent.$('#btn').click();
                     parent.$.jBox.close(true);
                     return flag;
            	}
            	   
                    /* window.parent.page();                                     //调用父窗体方法，当关闭子窗体刷新父窗体
                    window.parent.window.jBox.close(); */            //关闭子窗体
            },
            error : function(data){
            	alertx("无权限");
            }
        });
        return flag;
	}
	</script>
	<style type="text/css">	  
	  .row{
	  	padding: 6px 20px;
	  	margin: 0;
	  	border-bottom: 1px solid #ccc;
	  }
	  .col-md-4 {
	  	 float: left;
	     width: 20%;
	  }
	  .col-md-8 {
	  	float: right;
	  	width:79%
	  }
	</style>
</head>
<body>
	<div id="assignAuth">
		<form:form id="inputForm" enctype="multipart/form-data" modelAttribute="insTable" action="${ctx}/ins/insTable/assignAuth" method="post" class="breadcrumb form-search">
		<input type="hidden" id="username" value="${fns:getUser().name}"/>
		<div>
        	<ul class="ul-form">
				<li class="btns">
					<input type="file" name="file" id="myFile" class="input-medium"/>
				</li>
				<li id="fileSize"></li>
			</ul>
        	<input type="hidden" id="tableId" value="${insData.table.id}"/>
        </div>	
        </form:form>
    </div>
</body>
</html>
